<?php
/**
 * This is the FireFeed AddFeedBox form.
 * 
 * @uses       Zend_Form
 * @package    FireFeed
 * @subpackage Form
 */
class Form_Category extends Zend_Form
{
    /**
     * init() routine called when Zend_Form objects are created.
     * It make sense to define form elements in this method.
     * 
     * @see    http://framework.zend.com/manual/en/zend.form.html
     * @return void
     */ 
    public function init()
    {
        $this->setAction('/category/addcategory');
        $this->setMethod('POST');
        
        $this->setElementFilters(array('StringTrim'));
        
        $this->setAttrib('class', 'formstyle formAddCategories');
        $this->setAttrib('id', 'formcategory');

                
        // Add Name element
        $name = new Zend_Form_Element_Text('name');
        $name->setLabel('name')
             ->setAttrib('class', 'field')
             ->setAttrib('onkeyup','checkForRange(this, 4, 20);')
             ->setAttrib('onclick','checkForRange(this, 4, 20);')
             ->setDescription('msgNameCategory')
             ->setRequired(true)
             ->addValidator('StringLength', true, array('min'=> '4', 'max'=>'20'))
             ->setDecorators(array(
                   array('ViewHelper', array('helper'=>'formText')),
                   array('Label', array('class'=>'gray labelfield')),
                   array('Errors', array('tag' => 'span'))
        ));
                
        // Add Description element
        $description = new Zend_Form_Element_Textarea('description');
        $description->setLabel('descr')
                    ->setAttrib('class', 'field fieldtextareaBoxCategory')
                    ->setAttrib('onkeyup','checkForRange(this, 0, 255);')
                    ->setAttrib('onclick','checkForRange(this, 0, 255);')
                    ->setDescription('msgDescriptionCategory')
                    ->addValidator('StringLength', true, array('min'=> '0', 'max'=>'255'))
                    ->setDecorators(array(
                           array('ViewHelper'),
                           array('Label', array('class'=>'gray labelfield')),
                           array('Errors', array('tag' => 'span'))
        ));
                 
       
        // Add a submit button
        $submit = new Zend_Form_Element_Submit('save');
        $submit->setAttrib('class', 'smallSubmit')
               ->setDecorators(array(
                   array('ViewHelper', array('helper'=>'formSubmit'))
        ));
        
        $this->addElements(array(
            $name,
            $description,
            $submit
        ));
        
        $this->setDecorators(array(
            'FormElements',
            'Form'
        ));
    }
}